PLATFORM := $(shell uname -s)

CCFLAGS  = -Wall -g -Os
TODAY    = $(shell date +%Y%m%d)

TEXTS    = COPYING README SDL_COLLIDE_LICENSE font-copyright
DATA     = ball.png paddle.png bluebrick.png greenbrick.png orangebrick.png\
           redbrick.png purplebrick.png yellowbrick.png font.ttf icon16.bmp

PASSWORD =

.PHONY: clean tarball

ifeq (Linux, $(PLATFORM))
CC       = gcc
LIBS     = -lSDL -lSDL_image -lSDL_ttf
PYTHON   = /usr/bin/python
TAR      = /bin/tar
FILENAME = breakout-$(TODAY).tgz

default: breakout


# Linux targets:

lrelease: tarball
	$(PYTHON) googlecode_upload.py -s "Linux release du jour" -p jen-breakout --user=nmichaels -w $(PASSWORD) -l "Featured,Type-Executable,OpSys-Linux" $(FILENAME)

tarball: breakout
	$(TAR) -czf $(FILENAME) breakout $(DATA) $(TEXTS)

breakout: breakout.c levels.o highscores.o SDL_collide.o
	$(CC) $(CCFLAGS) $(LIBS) -o $@ $@.c levels.o SDL_collide.o highscores.o

SDL_collide.o: SDL_collide.c
	$(CC) -c $(CCFLAGS) -o SDL_collide.o SDL_collide.c

highscores.o: highscores.c
	$(CC) -c $(CCFLAGS) -o highscores.o highscores.c

else
CC       = /mingw/bin/gcc
PYTHON   = /c/cygwin/bin/python.exe
LIBS     = -lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_ttf
CCFLAGS += -DMINGW
LIB_PATH = -L/usr/local/lib/
SDLPATH  = /usr/local/include
ZIP     ?= /c/cygwin/bin/zip.exe
DLLS     = SDL.dll SDL_Image.dll SDL_ttf.dll zlib1.dll libpng12-0.dll
FILENAME = breakout-$(TODAY).zip

default: breakout.exe

# Windows targets:

wrelease: zipfile
	$(PYTHON) googlecode_upload.py -s "Windows release du jour" -p jen-breakout --user=nmichaels -w $(PASSWORD) -l "Featured,Type-Executable,OpSys-Windows" $(FILENAME)

zipfile: breakout.exe
	$(ZIP) $(FILENAME) breakout.exe $(TEXTS) $(DATA) $(DLLS)

icon.o: icon32.ico
	windres -i icon.rc -o icon.o

breakout.exe: breakout.c levels.o SDL_collide.o icon.o highscores.o
	$(CC) $(CCFLAGS) $(LIB_PATH) -I $(SDLPATH) -o $@ breakout.c levels.o SDL_collide.o highscores.o icon.o $(LIBS) 

SDL_collide.o: SDL_collide.c
	$(CC) -c $(CCFLAGS) -I $(SDLPATH) -o SDL_collide.o SDL_collide.c

highscores.o: highscores.c
	$(CC) -c $(CCFLAGS) -I $(SDLPATH) -o highscores.o highscores.c

endif

levels.inc: levelgen.py *.lvl
	$(PYTHON) levelgen.py > levels.inc

levels.o: levels.c levels.inc
	$(CC) -c $(CCFLAGS) -o levels.o levels.c

clean:
	rm -f breakout breakout.exe *.o *.zip *.tgz depends *.inc

depends:
	$(CC) -MM *.c > depends

-include depends

